package pailaidai.hc.com.mysvgdemo.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import pailaidai.hc.com.mysvgdemo.R;

/**
 * Created by Administrator on 2018/3/30.
 */

public class MyTextAndEditText extends LinearLayout {
    public MyTextAndEditText(Context context) {
        super(context);
    }

    public MyTextAndEditText(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyTextAndEditText(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
          int resouceld=-1;
        TypedArray typedArray=context.obtainStyledAttributes(attrs,R.styleable.MyTextAndEditText);
        TextView textView=new TextView(context);
        EditText editText=new EditText(context);
        int N=typedArray.getIndexCount();
        for (int i=0;i<N;i++){
            int arr=typedArray.getIndex(i);
            switch (arr){
                case R.styleable.MyTextAndEditText_Oriental:
                    resouceld=typedArray.getInt(R.styleable.MyTextAndEditText_Oriental,0);
                    setOrientation(resouceld==1?LinearLayout.HORIZONTAL:LinearLayout.VERTICAL);
                    break;
                case R.styleable.MyTextAndEditText_text:
                  resouceld=typedArray.getResourceId(R.styleable.MyTextAndEditText_text,0);
                    textView.setText(resouceld>0?typedArray.getResources().getText(resouceld):typedArray.getString(R.styleable.MyTextAndEditText_text));
                    break;
            }
            addView(textView);
            addView(editText);
            typedArray.recycle();
        }
    }



}
